package controllers

import (
	"GoIM/models"
	"github.com/astaxie/beego"
	"log"
)

type ApiController struct {
	beego.Controller
}

//获取主页数据面板 路由 /api/panel/msg
func (this *ApiController) PanelMsg() {
	username := this.GetString("username")
	pm := models.PanelMsg{}
	pm.Data.Mine = models.GetPersionInfo(username)
	fl := []models.FriendList{}
	fl = append(fl,models.FriendList{Gid:1,GroupName:"通讯录",List:models.GetAllUserList()})
	pm.Data.Friend = fl
	pm.Data.Group = models.GetAllGroupList()
	pm.Msg = "没有错误信息"
	pm.Code = 0
	this.Data["json"] = pm
	this.ServeJSON()
}

//修改签名时触发的ajax请求处理 路由 /api/info/sign/modify
func (this *ApiController) ModifySign() {
	username := this.GetString("username")
	sign := this.GetString("sign")
	log.Println(sign)
	info := ResultData{}
	if err := models.ModifySign(username,sign); err == nil{
		info = ResultData{Error:0}
	}else{
		info = ResultData{Error:1}
	}
	this.Data["json"] = info
	this.ServeJSON()
}
